package com.example.demo.controller;

import com.example.demo.annotation.Idempotent;
import com.example.demo.keyresolver.impl.ExpressionIdempotentKeyResolver;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * TODO
 *
 * @author houp
 * @since 1.0.0
 **/
@RestController
@Slf4j
public class IndexController {
    // https://www.jianshu.com/p/77895a822237

    @PostMapping("test/1")
    @Idempotent(message = "1111111111111111111")
    public String test1(String userName) {
        return "test1";
    }

    @PostMapping("test/2")
    @Idempotent
    public String test2(User user) {
        return "test2";
    }

    @PostMapping("test/3")
    @Idempotent
    public String test3(@RequestBody User user) {
        return "test3";
    }

    @PostMapping("test/4")
    @Idempotent(keyResolver = ExpressionIdempotentKeyResolver.class, keyArgs = {"#user"})
    public String test4(User user, User2 user2) {
        return "test4";
    }

    @PostMapping("test/5")
    @Idempotent(keyResolver = ExpressionIdempotentKeyResolver.class, keyArgs = {"#user2"})
    public String test5(@RequestBody User user, User2 user2) {
        return "test5";
    }

    @PostMapping("test/6")
    @Idempotent(keyResolver = ExpressionIdempotentKeyResolver.class, keyArgs = {"#user.test", "#user.test3","#user.id"})
    public String test6(@RequestBody User3 user) {
        return "test6";
    }

}
